home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: Why Do I Use An Ampersand in Member Class Parameters?
- Date: Thu, 01 Feb 1996 16:07:08 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4eqoee$bi5@news.halcyon.com>
- References: <4emnv2$n5o@alcor.usc.edu> <4empsa$18b@ixnews5.ix.netcom.com>
- NNTP-Posting-Host: blv-pm2-ip25.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- judgemi@ix.netcom.com (Michael Judge ) wrote:
-
- >In <4emnv2$n5o@alcor.usc.edu> wawda@alcor.usc.edu (Abu Wawda) writes:
- >>
- >>class Simple
- >>{
- >>public:
- >> Simple();
- >> int operator += (const Simple &);
- >>private:
- >> int data;
- >>};
- >>
- >>I have seen many examples of this but I what I don't understand is why
- >>there is an amersand after Simple? ...
- >>
- >>-Abu Wawda
- >> wawda@scf.usc.edu
- >>
- >>
-
- >I am not sure i understand this, but the & makes the parameter a
- >reference. That way a copy of simple is not made when the method is
- >used. Use & insted of * because you are more assured that the parameter
- >is a legal object. (unless someone did some evil casting)
-
- >note: i dont have my compiler with me but i dont think one simple
- >object can necessarily access another's private members without an
- >access method...If i am mistaken someone please correct me.
-
- It's fine for any Simple instance to access private data from any
- Simple instance passed in. Derivatives of Simple may not access
- private data of Simple, except by calling Simple methods explicitly.
-
- --Norm
-
-